__author__ = "jimmyorr@gmail.com (Jimmy Orr), chedbrandh@gmail.com (Christofer Hedbrandh)"

import os
import time

from dropio.client import *
from client_test_utils import *

class DropIoClientAssetActionsTestCase(DropIoClientBaseTestCase):

    def setUp(self):
        DropIoClientBaseTestCase.setUp(self)
        # create self.drop
        self.drop = self.client.create_drop(drop_name = self.available_drop_name)
    
    ################
    # create_link()
    ################
    
    def test_create_link(self):
        for c in filter(None, [self.client, self.secure_client]):
            test_url = "http://foo.com"
            test_title = "test_title"
            test_description = "test_description"
            asset = c.create_link(drop_name = self.drop.name, url = test_url, title = test_title, description = test_description)
            asset2 = c.get_asset(drop_name = self.drop.name, asset_name = asset.name)
            # todo created_at parameter format varies randomly, Bug #628
            self.failUnless(asset == asset2)
            self.failUnlessEqual(test_title, asset.title)
            self.failUnlessEqual(test_description, asset.description)
            self.failUnlessEqual(asset.type, "link")
            self.failUnless(asset.created_at)
            self.failUnless(asset.name)
            self.failUnlessEqual(asset.roles["original_content"]["filesize"], 0)
            self.failUnlessEqual(asset.roles["original_content"]["url"], test_url)
    
    def test_create_link_no_such_drop_name(self):
        for c in filter(None, [self.client, self.secure_client]):
            self.assertRaises(ResourceNotFoundError, c.create_link, drop_name = self.available_drop_name2, url = "http://foo.com")
    
    def test_create_link_unauthorized(self):
        assert self.client2 or self.secure_client2, "no second key specified"
        for c in filter(None, [self.client, self.secure_client]):
            for c2 in filter(None, [self.client2, self.secure_client2]):
                self.assertRaises(ForbiddenError, c2.create_link, drop = self.drop, url = "http://foo.com")

    ################
    # create_note()
    ################
    
    def test_create_note(self):
        for c in filter(None, [self.client, self.secure_client]):
            test_contents = "blah blah blah"
            test_title = "test_title"
            test_description = "test_description"
            asset = c.create_note(drop_name = self.drop.name, contents = test_contents, title = test_title, description = test_description)
            asset2 = c.get_asset(drop_name = self.drop.name, asset_name = asset.name)
            # todo created_at parameter format varies randomly, Bug #628
            self.failUnless(asset == asset2)
            self.failUnlessEqual(test_title, asset.title)
            self.failUnlessEqual(test_description, asset.description)
            self.failUnlessEqual(asset.type, "note")
            self.failUnless(asset.created_at)
            self.failUnless(asset.name)
            self.failUnlessEqual(asset.roles["original_content"]["contents"], test_contents)
    
    def test_create_note_no_such_drop_name(self):
        for c in filter(None, [self.client, self.secure_client]):
            self.assertRaises(ResourceNotFoundError, c.create_note, drop_name = self.available_drop_name2, contents = "asdf")
    
    def test_create_note_unauthorized(self):
        assert self.client2 or self.secure_client2, "no second key specified"
        for c in filter(None, [self.client, self.secure_client]):
            for c2 in filter(None, [self.client2, self.secure_client2]):
                self.assertRaises(ForbiddenError, c2.create_note, drop = self.drop, contents = "asdf")

    ################
    # create_file()
    ################

    def test_create_file_document_doc(self):
        for c in filter(None, [self.client, self.secure_client]):
            file_name = "test_document.doc"
            test_description = "test_description"
            asset = c.create_file(drop_name = self.drop.name, file_name = file_name, description = test_description)
            asset2 = c.get_asset(drop_name = self.drop.name, asset_name = asset.name)
            # todo not in docs what this should be
            #self.failUnlessEqual(??, asset.title)
            self.failUnlessEqual(test_description, asset.description)
            self.failUnlessEqual(asset.type, "document")
            self.failUnless(asset.created_at)
            self.failUnless(asset.name)
            self.failUnless(asset.roles["original_content"]["filesize"] > 0)
    
    def test_create_file_document_pdf(self):
        for c in filter(None, [self.client, self.secure_client]):
            file_name = "test_document.pdf"
            test_description = "test_description"
            asset = c.create_file(drop_name = self.drop.name, file_name = file_name, description = test_description)
            asset2 = c.get_asset(drop_name = self.drop.name, asset_name = asset.name)
            # todo not in docs what this should be
            #self.failUnlessEqual(??, asset.title)
            self.failUnlessEqual(test_description, asset.description)
            self.failUnlessEqual(asset.type, "document")
            self.failUnless(asset.created_at)
            self.failUnless(asset.name)
            self.failUnless(asset.roles["original_content"]["filesize"] > 0)
    
    def test_create_file_image_png(self):
        for c in filter(None, [self.client, self.secure_client]):
            file_name = TEST_IMAGE_PNG
            test_description = "test_description"
            asset = c.create_file(drop_name = self.drop.name, file_name = file_name, description = test_description)
            asset2 = c.get_asset(drop_name = self.drop.name, asset_name = asset.name)
            # todo not in docs what this should be
            #self.failUnlessEqual(??, asset.title)
            self.failUnlessEqual(test_description, asset.description)
            self.failUnlessEqual(asset.type, "image")
            self.failUnless(asset.created_at)
            self.failUnless(asset.name)
            self.failUnless(asset.roles["original_content"]["filesize"] > 0)
    
    def test_create_file_image_jpg(self):
        for c in filter(None, [self.client, self.secure_client]):
            file_name = TEST_IMAGE_JPG
            test_description = "test_description"
            asset = c.create_file(drop_name = self.drop.name, file_name = file_name, description = test_description)
            asset2 = c.get_asset(drop_name = self.drop.name, asset_name = asset.name)
            # todo not in docs what this should be
            #self.failUnlessEqual(??, asset.title)
            self.failUnlessEqual(test_description, asset.description)
            self.failUnlessEqual(asset.type, "image")
            self.failUnless(asset.created_at)
            self.failUnless(asset.name)
            self.failUnless(asset.roles["original_content"]["filesize"] > 0)
    
    def test_create_file_movie_flv(self):
        for c in filter(None, [self.client, self.secure_client]):
            file_name = TEST_MOVIE_FLV
            test_description = "test_description"
            asset = c.create_file(drop_name = self.drop.name, file_name = file_name, description = test_description)
            asset2 = c.get_asset(drop_name = self.drop.name, asset_name = asset.name)
            # todo not in docs what this should be
            #self.failUnlessEqual(??, asset.title)
            self.failUnlessEqual(test_description, asset.description)
            self.failUnlessEqual(asset.type, "movie")
            self.failUnless(asset.created_at)
            self.failUnless(asset.name)
            self.failUnless(asset.roles["original_content"]["filesize"] > 0)
            # todo documented duration parameter is not available
            self.failUnless(asset.roles["original_content"]["duration"] > 0)
    
    def test_create_file_audio_wav(self):
        for c in filter(None, [self.client, self.secure_client]):
            file_name = TEST_AUDIO_WAV
            test_description = "test_description"
            asset = c.create_file(drop_name = self.drop.name, file_name = file_name, description = test_description)
            asset2 = c.get_asset(drop_name = self.drop.name, asset_name = asset.name)
            # todo not in docs what this should be
            #self.failUnlessEqual(??, asset.title)
            self.failUnlessEqual(test_description, asset.description)
            self.failUnlessEqual(asset.type, "audio")
            self.failUnless(asset.created_at)
            self.failUnless(asset.name)
            self.failUnless(asset.roles["original_content"]["filesize"] > 0)
            # todo documented duration parameter is not available
            self.failUnless(asset.roles["original_content"]["duration"] > 0)
    
    def test_create_file_audio_mp3(self):
        for c in filter(None, [self.client, self.secure_client]):
            file_name = TEST_AUDIO_MP3
            test_description = "test_description"
            asset = c.create_file(drop_name = self.drop.name, file_name = file_name, description = test_description)
            asset2 = c.get_asset(drop_name = self.drop.name, asset_name = asset.name)
            # todo not in docs what this should be
            #self.failUnlessEqual(??, asset.title)
            self.failUnlessEqual(test_description, asset.description)
            self.failUnlessEqual(asset.type, "audio")
            self.failUnless(asset.created_at)
            self.failUnless(asset.name)
            self.failUnless(asset.roles["original_content"]["filesize"] > 0)
            # todo documented duration parameter is not available
            self.failUnless(asset.roles["original_content"]["duration"] > 0)
            # todo not availabel but is in documentation
            self.failUnlessEqual(asset.roles["original_content"]["artist"], "test_artist")
            # todo not availabel but is in documentation
            self.failUnlessEqual(asset.roles["original_content"]["track_title"], "test_title")
    
    def test_create_file_secure_client_open(self):
        if self.secure_client:
            file_name = TEST_IMAGE_JPG
            test_description = "test_description"
            asset = self.secure_client.create_file(drop_name = self.drop.name, file_name = file_name, description = test_description, signature_mode = 'OPEN')
            self.failUnlessEqual(test_description, asset.description)
        
    def test_create_file_secure_client_normal(self):
        if self.secure_client:
            file_name = TEST_IMAGE_JPG
            test_description = "test_description"
            asset = self.secure_client.create_file(drop_name = self.drop.name, file_name = file_name, description = test_description, signature_mode = 'NORMAL')
            self.failUnlessEqual(test_description, asset.description)
        
    def test_create_file_secure_client_strict(self):
        if self.secure_client:
            file_name = TEST_IMAGE_JPG
            test_description = "test_description"
            asset = self.secure_client.create_file(drop_name = self.drop.name, file_name = file_name, description = test_description, signature_mode = 'STRICT')
            self.failUnlessEqual(test_description, asset.description)
    
    def test_create_file_no_such_file_name(self):
        for c in filter(None, [self.client, self.secure_client]):
            self.assertRaises(Exception, c.create_file, drop = self.drop, file_name = "asdf")
    
    def test_create_file_no_such_drop_name(self):
        for c in filter(None, [self.client, self.secure_client]):
            # todo drops that dont exist are created
            self.assertRaises(ResourceNotFoundError, c.create_file, drop_name = self.available_drop_name2, file_name = TEST_IMAGE_JPG)
    
    def test_create_file_unauthorized(self):
        assert self.client2 or self.secure_client2, "no second key specified"
        for c in filter(None, [self.client, self.secure_client]):
            for c2 in filter(None, [self.client2, self.secure_client2]):
                # todo does not return an error Bug #691
                self.assertRaises(ForbiddenError, c2.create_file, drop = self.drop, file_name = TEST_IMAGE_JPG)

    
    
    ################
    # create_file_from_url()
    ################

    def test_create_file_from_url_image_gif(self):
        for c in filter(None, [self.client, self.secure_client]):
            test_file_url = TEST_FILE_IMAGE_GIF_URL
            test_description = "test_description"
            asset = c.create_file_from_url(drop_name = self.drop.name, file_url = test_file_url, description = test_description)
            # wait for asset to be fetched
            time.sleep(PROCESS_WAIT_TIME * 30)
            asset = c.get_asset(drop_name = self.drop.name, asset_name = asset.name)
            # todo not in docs what this should be
            #self.failUnlessEqual(??, asset.title)
            # todo, bug, description is lost
            self.failUnlessEqual(test_description, asset.description)
            self.failUnlessEqual(asset.type, "image")
            self.failUnless(asset.created_at)
            self.failUnless(asset.name)
            self.failUnless(asset.roles["original_content"]["filesize"] > 0)
    
    # todo actually not sure what should happen here
    def test_create_file_from_url_no_such_url(self):
        for c in filter(None, [self.client, self.secure_client]):
            self.assertRaises(ResourceNotFoundError, c.create_file_from_url, drop = self.drop, file_url = "http://foo.com")
    
    def test_create_file_from_url_no_such_drop_name(self):
        for c in filter(None, [self.client, self.secure_client]):
            self.assertRaises(ResourceNotFoundError, c.create_file_from_url, drop_name = self.available_drop_name2, file_url = TEST_FILE_IMAGE_GIF_URL)
    
    def test_create_file_from_url_unauthorized(self):
        assert self.client2 or self.secure_client2, "no second key specified"
        for c in filter(None, [self.client, self.secure_client]):
            for c2 in filter(None, [self.client2, self.secure_client2]):
                self.assertRaises(ForbiddenError, c2.create_file_from_url, drop = self.drop, file_url = TEST_FILE_IMAGE_GIF_URL)

    
    ###################
    # get_assets()
    ###################

    def test_get_assets(self):
        for c in filter(None, [self.client, self.secure_client]):
            asset_list = []
            # note assets
            for i in range(31):
                asset_list.append(c.create_note(drop = self.drop, contents = str(i)))
            # link asset
            test_url = "http://foo.com"
            asset_list.append(c.create_link(drop = self.drop, url = test_url))
            # file image asset
            file_name = TEST_IMAGE_PNG
            asset_list.append(c.create_file(drop = self.drop, file_name = file_name))
            # file audio asset
            file_name = "test_audio.wav"
            asset_list.append(c.create_file(drop = self.drop, file_name = file_name))
            asset_list = [c.get_asset(drop = self.drop, asset_name = a.name) for a in asset_list]
            asset_list_get_assets = list(c.get_assets(drop = self.drop))
            # todo, this fails due to, created_at parameter format varies randomly, Bug #628
            for a in asset_list:
                 self.failUnless(a in asset_list_get_assets)
       
    def test_get_assets_no_such_drop_name(self):
        for c in filter(None, [self.client, self.secure_client]):
            gen = c.get_assets(drop_name = self.available_drop_name2)
            self.assertRaises(ResourceNotFoundError, gen.next)
    
    def test_get_assets_unauthorized(self):
        assert self.client2 or self.secure_client2, "no second key specified"
        for c in filter(None, [self.client, self.secure_client]):
            for c2 in filter(None, [self.client2, self.secure_client2]):
                c.create_file(drop = self.drop, file_name = TEST_IMAGE_JPG)
                gen = c2.get_assets(drop_name = self.available_drop_name2)
                self.assertRaises(ResourceNotFoundError, gen.next)

    ##############
    # get_asset()
    ##############

    def test_get_asset_no_such_asset_name(self):
        for c in filter(None, [self.client, self.secure_client]):
            self.assertRaises(ResourceNotFoundError, c.get_asset, drop_name = self.available_drop_name, asset_name = "asdf")
    
    def test_get_asset_no_such_drop_name(self):
        for c in filter(None, [self.client, self.secure_client]):
            self.assertRaises(ResourceNotFoundError, c.get_asset, drop_name = self.available_drop_name2, asset_name = "asdf")
    
    def test_get_asset_unauthorized(self):
        assert self.client2 or self.secure_client2, "no second key specified"
        for c in filter(None, [self.client, self.secure_client]):
            for c2 in filter(None, [self.client2, self.secure_client2]):
                asset = c.create_file(drop = self.drop, file_name = TEST_IMAGE_JPG)
                self.assertRaises(ForbiddenError, c2.get_asset, drop = self.drop, asset_name = asset.name)

    
    #################
    # update_asset()
    #################
    
    def test_update_asset_link(self):
        for c in filter(None, [self.client, self.secure_client]):
            test_url = "http://foo.com"
            test_title = "test_title"
            test_description = "test_description"
            test_url2 = test_url + "2"
            test_title2 = test_title + "2"
            test_description2 = test_description + "2"
            asset = c.create_link(drop_name = self.drop.name, url = test_url, title = test_title, description = test_description)
            asset2 = c.update_asset(drop = self.drop, asset = asset, url = test_url2, title = test_title2, description = test_description2)
            self.failUnlessEqual(asset2.title, test_title2)
            self.failUnlessEqual(asset2.roles['original_content']['url'], test_url2)
            self.failUnlessEqual(asset2.description, test_description2)
        
    def test_update_asset_link_from_asset_object(self):
        for c in filter(None, [self.client, self.secure_client]):
            test_url = "http://foo.com"
            test_title = "test_title"
            test_description = "test_description"
            test_url2 = test_url + "2"
            test_title2 = test_title + "2"
            test_description2 = test_description + "2"
            asset = c.create_link(drop_name = self.drop.name, url = test_url, title = test_title, description = test_description)
            asset.url = test_url2
            asset.title = test_title2
            asset.description = test_description2
            asset2 = c.update_asset(drop = self.drop, asset = asset)
            self.failUnlessEqual(asset2.title, test_title2)
            self.failUnlessEqual(asset2.roles['original_content']['url'], test_url2)
            self.failUnlessEqual(asset2.description, test_description2)
        
    def test_update_asset_note(self):
        for c in filter(None, [self.client, self.secure_client]):
            test_contents = "test_content"
            test_contents2 = test_contents + "2"
            asset = c.create_note(drop_name = self.drop.name, contents = test_contents)
            asset2 = c.update_asset(drop = self.drop, asset = asset, contents = test_contents2)
            self.failUnlessEqual(asset2.roles['original_content']['contents'], test_contents2)
        
    def test_update_asset_file_image_jpg(self):
        for c in filter(None, [self.client, self.secure_client]):
            test_file = TEST_IMAGE_JPG
            test_title = "test_title"
            test_description = "test_description"
            test_title2 = test_title + "2"
            test_description2 = test_description + "2"
            asset = c.create_file(drop_name = self.drop.name, file_name = test_file, description = test_description)
            asset2 = c.update_asset(drop = self.drop, asset = asset, title = test_title2, description = test_description2)
            self.failUnlessEqual(asset2.title, test_title2)
            self.failUnlessEqual(asset2.description, test_description2)
    
    def test_update_asset_no_such_asset_name(self):
        for c in filter(None, [self.client, self.secure_client]):
            self.assertRaises(ResourceNotFoundError, c.update_asset, drop_name = self.available_drop_name, asset_name = "asdf", description = "test_description")
    
    def test_update_asset_no_such_drop_name(self):
        for c in filter(None, [self.client, self.secure_client]):
            self.assertRaises(ResourceNotFoundError, c.update_asset, drop_name = self.available_drop_name2, asset_name = "asdf", description = "test_description")
    
    def test_update_asset_unauthorized(self):
        assert self.client2 or self.secure_client2, "no second key specified"
        for c in filter(None, [self.client, self.secure_client]):
            for c2 in filter(None, [self.client2, self.secure_client2]):
                asset = c.create_file(drop = self.drop, file_name = TEST_IMAGE_JPG)
                self.assertRaises(ForbiddenError, c2.update_asset, drop = self.drop, asset_name = asset.name, description = "test_description")

    
        
    #################
    # delete_asset()
    #################
    
    def test_delete_asset_file_image_jpg(self):
        for c in filter(None, [self.client, self.secure_client]):
            test_file = TEST_IMAGE_JPG
            asset = c.create_file(drop = self.drop, file_name = test_file)
            self.failUnlessEqual(len(list(c.get_assets(drop = self.drop))), 1)
            c.delete_asset(drop = self.drop, asset = asset)
            self.failUnlessEqual(len(list(c.get_assets(drop = self.drop))), 0)
    
    def test_delete_asset_no_such_asset_name(self):
        for c in filter(None, [self.client, self.secure_client]):
            self.assertRaises(ResourceNotFoundError, c.delete_asset, drop_name = self.available_drop_name, asset_name = "asdf")
    
    def test_delete_asset_no_such_drop_name(self):
        for c in filter(None, [self.client, self.secure_client]):
            self.assertRaises(ResourceNotFoundError, c.delete_asset, drop_name = self.available_drop_name2, asset_name = "asdf")
    
    def test_delete_asset_unauthorized(self):
        assert self.client2 or self.secure_client2, "no second key specified"
        for c in filter(None, [self.client, self.secure_client]):
            for c2 in filter(None, [self.client2, self.secure_client2]):
                asset = c.create_file(drop = self.drop, file_name = TEST_IMAGE_JPG)
                self.assertRaises(ForbiddenError, c2.delete_asset, drop = self.drop, asset = asset)

    ###############
    # copy_asset()
    ###############

    def test_copy_asset_file_image_jpg(self):
        for c in filter(None, [self.client, self.secure_client]):
            test_file = TEST_IMAGE_JPG
            asset = c.create_file(drop = self.drop, file_name = test_file)
            drop2 = c.create_drop(drop_name = self.available_drop_name2)
            c.copy_asset(target_drop = drop2, drop = self.drop, asset = asset)
            # wait for processing
            time.sleep(PROCESS_WAIT_TIME * 3)
            self.failUnless(c.get_asset(drop = drop2, asset_name = asset.name))
            # clean up
            c.delete_drop(drop = drop2)
            c.delete_asset(drop = self.drop, asset = asset)

    def test_copy_asset_no_such_asset_name(self):
        for c in filter(None, [self.client, self.secure_client]):
            self.assertRaises(ResourceNotFoundError, c.copy_asset, drop_name = self.available_drop_name, asset_name = "asdf", target_drop_name = self.available_drop_name2)
    
    def test_copy_asset_no_such_target_drop_name(self):
        for c in filter(None, [self.client, self.secure_client]):
            asset = c.create_file(drop = self.drop, file_name = TEST_IMAGE_JPG)
            self.assertRaises(ResourceNotFoundError, c.copy_asset, drop_name = self.available_drop_name, asset = asset, target_drop_name = self.available_drop_name2)
    
    def test_copy_asset_no_such_drop_name(self):
        for c in filter(None, [self.client, self.secure_client]):
            asset = c.create_file(drop = self.drop, file_name = TEST_IMAGE_JPG)
            self.assertRaises(ResourceNotFoundError, c.copy_asset, drop_name = self.available_drop_name2, asset = asset, target_drop_name = self.available_drop_name)
    
    def test_copy_asset_unauthorized(self):
        assert self.client2 or self.secure_client2, "no second key specified"
        for c in filter(None, [self.client, self.secure_client]):
            for c2 in filter(None, [self.client2, self.secure_client2]):
                asset = c.create_file(drop = self.drop, file_name = TEST_IMAGE_JPG)
                drop2 = c.create_drop(drop_name = self.available_drop_name2)
                self.assertRaises(ForbiddenError, c2.copy_asset, drop = self.drop, asset = asset, target_drop = drop2)
    
    def test_copy_asset_unauthorized_copy_from(self):
        assert self.client2 or self.secure_client2, "no second key specified"
        for c in filter(None, [self.client, self.secure_client]):
            for c2 in filter(None, [self.client2, self.secure_client2]):
                asset = c.create_file(drop = self.drop, file_name = TEST_IMAGE_JPG)
                drop2 = c2.create_drop(drop_name = self.available_drop_name2)
                self.assertRaises(ForbiddenError, c2.copy_asset, drop = self.drop, asset = asset, target_drop = drop2)
    
    def test_copy_asset_unauthorized_copy_to(self):
        assert self.client2 or self.secure_client2, "no second key specified"
        for c in filter(None, [self.client, self.secure_client]):
            for c2 in filter(None, [self.client2, self.secure_client2]):
                asset = c.create_file(drop = self.drop, file_name = TEST_IMAGE_JPG)
                drop2 = c2.create_drop(drop_name = self.available_drop_name2)
                self.assertRaises(ForbiddenError, c.copy_asset, drop = self.drop, asset = asset, target_drop = drop2)
    
    ###############
    # move_asset()
    ###############

    def test_move_asset_file_image_jpg(self):
        for c in filter(None, [self.client, self.secure_client]):
            test_file = TEST_IMAGE_JPG
            asset = c.create_file(drop = self.drop, file_name = test_file)
            drop2 = c.create_drop(drop_name = self.available_drop_name2)
            c.move_asset(target_drop = drop2, drop = self.drop, asset = asset)
            # wait for processing
            time.sleep(PROCESS_WAIT_TIME * 3)
            self.failUnless(c.get_asset(drop = drop2, asset_name = asset.name))
            self.failUnlessRaises(ResourceNotFoundError, c.get_asset, drop = self.drop, asset = asset)
            self.failUnlessEqual(len(list(c.get_assets(drop = self.drop))), 0)
            self.failUnlessEqual(len(list(c.get_assets(drop = drop2))), 1)
            # clean up
            c.delete_drop(drop = drop2)

    def test_move_asset_no_such_asset_name(self):
        for c in filter(None, [self.client, self.secure_client]):
            self.assertRaises(ResourceNotFoundError, c.move_asset, drop_name = self.available_drop_name, asset_name = "asdf", target_drop_name = self.available_drop_name2)
    
    def test_move_asset_no_such_target_drop_name(self):
        for c in filter(None, [self.client, self.secure_client]):
            asset = c.create_file(drop = self.drop, file_name = TEST_IMAGE_JPG)
            self.assertRaises(ResourceNotFoundError, c.move_asset, drop_name = self.available_drop_name, asset = asset, target_drop_name = self.available_drop_name2)
    
    def test_move_asset_no_such_drop_name(self):
        for c in filter(None, [self.client, self.secure_client]):
            asset = c.create_file(drop = self.drop, file_name = TEST_IMAGE_JPG)
            self.assertRaises(ResourceNotFoundError, c.move_asset, drop_name = self.available_drop_name2, asset = asset, target_drop_name = self.available_drop_name)
    
    def test_move_asset_unauthorized(self):
        assert self.client2 or self.secure_client2, "no second key specified"
        for c in filter(None, [self.client, self.secure_client]):
            for c2 in filter(None, [self.client2, self.secure_client2]):
                asset = c.create_file(drop = self.drop, file_name = TEST_IMAGE_JPG)
                drop2 = c.create_drop(drop_name = self.available_drop_name2)
                self.assertRaises(ForbiddenError, c2.move_asset, drop = self.drop, asset = asset, target_drop = drop2)
    
    def test_move_asset_unauthorized_move_from(self):
        assert self.client2 or self.secure_client2, "no second key specified"
        for c in filter(None, [self.client, self.secure_client]):
            for c2 in filter(None, [self.client2, self.secure_client2]):
                asset = c.create_file(drop = self.drop, file_name = TEST_IMAGE_JPG)
                drop2 = c2.create_drop(drop_name = self.available_drop_name2)
                self.assertRaises(ForbiddenError, c2.move_asset, drop = self.drop, asset = asset, target_drop = drop2)
    
    def test_move_asset_unauthorized_move_to(self):
        assert self.client2 or self.secure_client2, "no second key specified"
        for c in filter(None, [self.client, self.secure_client]):
            for c2 in filter(None, [self.client2, self.secure_client2]):
                asset = c.create_file(drop = self.drop, file_name = TEST_IMAGE_JPG)
                drop2 = c2.create_drop(drop_name = self.available_drop_name2)
                self.assertRaises(ForbiddenError, c.move_asset, drop = self.drop, asset = asset, target_drop = drop2)
    
    
    ###############
    # download_asset_original_file()
    ###############
    
    def test_download_asset_original_file(self):
        for c in filter(None, [self.client, self.secure_client]):
            save_file_name = "test_download_file"
            asset = c.create_file(drop = self.drop, file_name = TEST_IMAGE_JPG)
            c.download_asset_original_file(file_name = save_file_name, drop = self.drop, asset = asset)
            self.failUnless(os.path.isfile(save_file_name))
            os.remove(save_file_name)
    
    def test_download_asset_no_such_asset_name(self):
        for c in filter(None, [self.client, self.secure_client]):
            self.assertRaises(ResourceNotFoundError, c.download_asset_original_file, drop_name = self.available_drop_name, asset_name = "asdfqwerxcv", file_name = "test_download_file")
    
    def test_download_asset_no_such_drop_name(self):
        for c in filter(None, [self.client, self.secure_client]):
            asset = c.create_file(drop = self.drop, file_name = TEST_IMAGE_JPG)
            self.assertRaises(ResourceNotFoundError, c.download_asset_original_file, drop_name = self.available_drop_name2, asset = asset, file_name = "test_download_file")
    
    def test_download_asset_unauthorized(self):
        assert self.client2 or self.secure_client2, "no second key specified"
        for c in filter(None, [self.client, self.secure_client]):
            for c2 in filter(None, [self.client2, self.secure_client2]):
                asset = c.create_file(drop = self.drop, file_name = TEST_IMAGE_JPG)
                self.assertRaises(ForbiddenError, c2.download_asset_original_file, drop = self.drop, asset = asset, file_name = "test_download_file")
